/**
 * 规则栈
 */
export default class RuleStack{


    constructor(){
        this.list=new Array();
        this.list.push({pid:0,rule:[]})
    }

    /**
     * 添加规则列表
     * @param rules
     * @param pid
     */
    addRules(rules,pid){

        for(let i=0;i<rules.length;i++){
            this.list.push({pid:pid,rule:rules[i]})
        }
    }

    /**
     * 语法正则对比
     * @param nouns
     * @returns {number}
     */
    isNouns(nouns){
        for(let i=this.list.length;i>0;i--){
            if(this.isNoun(this.list[i].rule,nouns)){
                return i;
            }
        }
        return 0;
    }

    isNoun(rule,nouns){
        let is=0;
        for(let i=0;i<nouns.length-1;i++){
            if(nouns[i]==rule[i]){
                is++;
            }
        }
        if(is==rule.length-1){
            return true;
        }
        return false;

    }
}